package com.lagou.niancheng.rpc.common.handler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 请求处理器注册中心
 *
 * @author 大犬
 * @date 2020/4/30
 */
public class RequestHandlerRegistry {
    private Map<Class, RequestHandler> resultHandlerMap;

    public RequestHandlerRegistry() {
        resultHandlerMap = new ConcurrentHashMap<>();
    }

    public <T> void register(Class<? extends T> dataType, RequestHandler<T> requestHandler) {
        resultHandlerMap.put(dataType, requestHandler);
    }

    public RequestHandler getRequestHandler(Class dataType) {
        return resultHandlerMap.get(dataType);
    }
}
